<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="Cask Data, Inc." name="author" />
<meta content="Copyright © 2015-2016 Cask Data, Inc." name="copyright" />


    <meta name="git_release" content="6.1.1">
    <meta name="git_hash" content="05fbac36f9f7aadeb44f5728cea35136dbc243e5">
    <meta name="git_timestamp" content="2020-02-09 08:22:47 +0800">
    <title>Cube Dataset</title>

    <link rel="stylesheet" href="../../_static/cdap-bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/bootstrap-3.3.6/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/bootstrap-3.3.6/css/bootstrap-theme.min.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/bootstrap-sphinx.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/cdap-dynamicscrollspy-4.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/jquery.mCustomScrollbar.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/cdap-jquery.mCustomScrollbar.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/abixTreeList-2.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/cdap-bootstrap.css" type="text/css" />

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '6.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>

    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="top" title="Cask Data Application Platform 6.1.1 Documentation" href="../../index.html" />
    <link rel="up" title="Datasets" href="index.html" />
    <link rel="next" title="MapReduce Programs" href="../mapreduce-programs.html" />
    <link rel="prev" title="Dataset Permissions" href="permissions.html" />
    <!-- block extrahead -->
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <!-- block extrahead end -->

</head>
<body role="document">

<!-- block navbar -->
<div id="navbar" class="navbar navbar-inverse navbar-default navbar-fixed-top">
    <div class="container-fluid">
      <div class="row">
        <div class="navbar-header">
          <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
          <a class="navbar-brand" href="../../table-of-contents/../../index.html">
            <span><img alt="CDAP logo" src="../../_static/cdap_logo.svg"/></span>
          </a>

          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>

          <div class="pull-right">
            <div class="dropdown version-dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                role="button" aria-haspopup="true" aria-expanded="false">
                v 6.1.1 <span class="caret"></span>
              </a>
              <ul class="dropdown-menu">
                <li><a href="//docs.cdap.io/cdap/5.1.2/en/index.html">v 5.1.2</a></li>
                <li><a href="//docs.cdap.io/cdap/4.3.4/en/index.html">v 4.3.4</a></li>
              </ul>
            </div>
          </div>
          <form class="navbar-form navbar-right navbar-search" action="../../search.html" method="get">
            <div class="form-group">
              <div class="navbar-search-image material-icons"></div>
              <input type="text" name="q" class="form-control" placeholder="  Search" />
            </div>
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>

          <div class="collapse navbar-collapse nav-collapse navbar-right navbar-navigation">
            <ul class="nav navbar-nav"><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="../../table-of-contents/../../index.html">简介</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link current" href="../../table-of-contents/../../guides.html">手册</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="../../table-of-contents/../../reference-manual/index.html">参考</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="../../table-of-contents/../../faqs/index.html">帮助</a></li>
            </ul>
          </div>

        </div>
      </div>
    </div>
  </div><!-- block navbar end -->
<!-- block main content -->
<div class="main-container container">
  <div class="row"><div class="col-md-2">
      <div id="sidebar" class="bs-sidenav scrollable-y-outside" role="complementary">
<!-- theme_manual: developer-manual -->
<!-- theme_manual_highlight: guides -->
<!-- sidebar_title_link: ../../table-of-contents/../../guides.html -->

  <div role="note" aria-label="manuals links"><h3><a href="../../table-of-contents/../../guides.html">Guides</a></h3>

    <ul class="this-page-menu">
      <li class="toctree-l1"><a href="../../table-of-contents/../../user-guide/index.html" rel="nofollow">用户手册</a>
      </li>
      <li class="toctree-l1"><b><a href="../../table-of-contents/../../developer-manual/index.html" rel="nofollow">开发手册</a></b>
      <nav class="pagenav">
      <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../index.html"> 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started/index.html"> 入门指南</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/sandbox/index.html">CDAP Sandbox</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/zip.html">二进制 Zip 文件</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/zip.html#cdap-sandbox">启动和停止 CDAP Sandbox</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/virtual-machine.html">虚拟机镜像</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/docker.html">Docker 镜像</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/quick-start.html">快速入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/dev-env.html">搭建开发环境</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/start-stop-cdap.html">启动和停止 CDAP</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/building-apps.html">构建并运行应用</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../overview/index.html"> 概述</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../overview/anatomy.html"> 大数据应用剖析</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../overview/modes.html"> 模式和组件</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../overview/abstractions.html"> 核心概念</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../overview/interfaces.html"> 编程接口</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html"> 抽象概念</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../core.html"> Core Abstractions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../applications.html"> Applications</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html"> Datasets</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="overview.html"> Overview</a></li>
<li class="toctree-l3"><a class="reference internal" href="table.html"> Table API</a></li>
<li class="toctree-l3"><a class="reference internal" href="fileset.html"> FileSets</a></li>
<li class="toctree-l3"><a class="reference internal" href="partitioned-fileset.html"> Partitioned FileSets</a></li>
<li class="toctree-l3"><a class="reference internal" href="time-partitioned-fileset.html"> TimePartitioned FileSets</a></li>
<li class="toctree-l3"><a class="reference internal" href="system-custom.html"> System and Custom Datasets</a></li>
<li class="toctree-l3"><a class="reference internal" href="permissions.html"> Dataset Permissions</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> Cube Dataset</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mapreduce-programs.html"> MapReduce Programs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../plugins.html"> Plugins</a></li>
<li class="toctree-l2"><a class="reference internal" href="../schedules.html"> Schedules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../secure-keys.html"> Secure Keys</a></li>
<li class="toctree-l2"><a class="reference internal" href="../services.html"> Services</a></li>
<li class="toctree-l2"><a class="reference internal" href="../spark-programs.html"> Spark Programs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../workers.html"> Workers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../workflows.html"> Workflows</a></li>
<li class="toctree-l2"><a class="reference internal" href="../artifacts.html"> Artifacts</a></li>
<li class="toctree-l2"><a class="reference internal" href="../program-lifecycle.html"> Program Lifecycle</a></li>
<li class="toctree-l2"><a class="reference internal" href="../namespaces.html"> Namespaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../transaction-system.html"> Transaction System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../transactional-messaging-system.html"> Transactional Messaging System</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../metadata/index.html"> 元数据</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/system-metadata.html"> System Metadata</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/discovery-lineage.html"> Discovery and Lineage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/field-lineage.html"> Field Level Lineage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/audit-logging.html"> Audit Logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/metadata-ui.html"> CDAP Metadata UI</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/programmatic-metadata.html"> Accessing metadata programmatically</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../pipelines/index.html"> 数据流管道</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/concepts-design.html"> Concepts and Design</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/getting-started.html"> Getting Started</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/studio.html"> CDAP Studio</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/creating-pipelines.html"> Creating Pipelines</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/running-pipelines.html"> Running Pipelines</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/plugin-management.html"> Plugin Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/plugins/index.html"> Plugin Reference</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/actions/index.html"> Action Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/sources/index.html"> Source Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/transforms/index.html"> Transform Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/analytics/index.html"> Analytic Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/sinks/index.html"> Sink Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/shared-plugins/index.html"> Shared Plugins</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../pipelines/plugins/shared-plugins/core.html">CoreValidator</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/post-run-plugins/index.html"> Post-run Plugins</a><ul class="simple">
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/developing-pipelines.html"> Developing Pipelines</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/developing-plugins/index.html"> Developing Plugins</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/plugin-basics.html">Plugin Basics</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/creating-a-plugin.html">Creating a Plugin</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/presentation-plugins.html">Plugin Presentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/testing-plugins.html">Testing Plugins</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/packaging-plugins.html">Packaging Plugins</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/how-cdap-pipelines-work.html"> How CDAP Pipelines Work</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../cloud-runtimes/index.html"> 云平台运行</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/concepts/index.html"> Concepts</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/provisioners/index.html"> Provisioners</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/provisioners/gcp-dataproc.html">Google Dataproc</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/provisioners/aws-emr.html">Amazon Elastic MapReduce</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/provisioners/remote-hadoop.html">Remote Hadoop</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/profiles/index.html"> Profiles</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/profiles/creating-profiles.html">Creating Profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/profiles/assigning-profiles.html">Assigning Profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/profiles/admin-controls.html">Admin Controls</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/example/index.html"> Example</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../security/index.html"> 安全</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../security/client-authentication.html">Client Authentication</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/cdap-authentication-clients-java.html">CDAP Authentication Client for Java</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/cdap-authentication-clients-python.html">CDAP Authentication Client for Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/custom-authentication.html">Custom Authentication</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/authorization-extensions.html">Authorization Extensions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../testing/index.html"> 测试和调试</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../testing/testing.html"> Testing a CDAP Application</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../testing/debugging.html"> Debugging</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../testing/troubleshooting.html"> Troubleshooting</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../ingesting-tools/index.html"> 数据融合</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-stream-clients-java.html">CDAP Stream Client for Java</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-stream-clients-python.html">CDAP Stream Client for Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-stream-clients-ruby.html">CDAP Stream Client for Ruby</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-flume.html">CDAP Flume</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../data-exploration/index.html"> 数据探索</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/filesets.html"> Fileset Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/tables.html"> Table Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/object-mapped-tables.html"> ObjectMappedTable Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/custom-datasets.html"> Custom Dataset Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/hive-execution-engines.html"> Hive Execution Engines</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../advanced/index.html"> 高级主题</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/application-logback.html"> Application Logback</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/best-practices.html"> Best Practices</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/class-loading.html"> Class Loading</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/configuring-resources.html"> Configuring Program Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/program-retry-policies.html"> Program Retry Policies</a></li>
</ul>
</li>
</ul>
</nav>
      </li>
      <li class="toctree-l1"><a href="../../table-of-contents/../../admin-manual/index.html" rel="nofollow">管理手册</a>
      </li>
      <li class="toctree-l1"><a href="../../table-of-contents/../../integrations/index.html" rel="nofollow">集成手册</a>
      </li>
      <li class="toctree-l1"><a href="../../table-of-contents/../../examples-manual/index.html" rel="nofollow">最佳实践</a>
      </li>
    </ul>
  </div></div>
    </div><div class="col-md-8 content" id="main-content">
    
  <div class="section" id="cube-dataset">
<span id="datasets-cube"></span><h1>Cube Dataset<a class="headerlink" href="#cube-dataset" title="Permalink to this headline">🔗</a></h1>
<div class="section" id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">🔗</a></h2>
<p>A <a class="reference external" href="../../../reference-manual/javadocs/io/cdap/cdap/api/dataset/lib/cube/package-summary.html">Cube dataset</a>
is an implementation of an <a class="reference external" href="http://en.wikipedia.org/wiki/OLAP_cube">OLAP Cube</a> that is
pre-packaged with CDAP. Cube datasets store multidimensional facts and provide a querying
interface for the retrieval of the data. Additionally, Cube datasets allows for
exploring of the data stored in the Cube.</p>
</div>
<div class="section" id="storing-data">
<h2>Storing Data<a class="headerlink" href="#storing-data" title="Permalink to this headline">🔗</a></h2>
<p>A Cube dataset stores multidimensional <code class="docutils literal notranslate"><span class="pre">CubeFacts</span></code> that contain dimension values,
measurements, and an associated timestamp:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">class</span> <span class="nc">CubeFact</span> <span class="p">{</span>
 <span class="kd">public</span> <span class="nf">CubeFact</span><span class="p">(</span><span class="kt">long</span> <span class="n">timestamp</span><span class="p">)</span> <span class="p">{...}</span>
 <span class="kd">public</span> <span class="n">CubeFact</span> <span class="nf">addDimensionValue</span><span class="p">(</span><span class="n">String</span> <span class="n">name</span><span class="p">,</span> <span class="n">String</span> <span class="n">value</span><span class="p">)</span> <span class="p">{...}</span>
 <span class="kd">public</span> <span class="n">CubeFact</span> <span class="nf">addMeasurement</span><span class="p">(</span><span class="n">String</span> <span class="n">name</span><span class="p">,</span> <span class="n">MeasureType</span> <span class="n">type</span><span class="p">,</span> <span class="kt">long</span> <span class="n">value</span><span class="p">)</span> <span class="p">{...}</span>
 <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Where:</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">timestamp</span></code> is an epoch in seconds</li>
<li>Dimension values are key-value pairs of a dimension <code class="docutils literal notranslate"><span class="pre">name</span></code> and <code class="docutils literal notranslate"><span class="pre">value</span></code></li>
<li>Measurements have a <code class="docutils literal notranslate"><span class="pre">name</span></code>, <code class="docutils literal notranslate"><span class="pre">type</span></code>, and <code class="docutils literal notranslate"><span class="pre">value</span></code></li>
</ul>
<p>An example of a fact could be data collected by a OS monitoring tool from a server at a
specific time:</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">timestamp=1429929000</span></code> <em>(equivalent to Sat, 25 Apr 2015 02:29:59 GMT)</em></li>
<li><code class="docutils literal notranslate"><span class="pre">dimensions</span></code><ul>
<li><code class="docutils literal notranslate"><span class="pre">rackId=&quot;rack1&quot;</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">serverId=&quot;server0002&quot;</span></code></li>
</ul>
</li>
<li><code class="docutils literal notranslate"><span class="pre">measurements</span></code><ul>
<li><code class="docutils literal notranslate"><span class="pre">cpu.used(gauge)=60</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">disk.reads(counter)=23244</span></code></li>
</ul>
</li>
</ul>
<p>Currently, two types of measurements are supported: gauge and counter. A <em>gauge</em>
measurement is for an absolute metric (it overwrites) while a <em>counter</em> measurement is for
an incremental metric.</p>
</div>
<div class="section" id="writing-data">
<h2>Writing Data<a class="headerlink" href="#writing-data" title="Permalink to this headline">🔗</a></h2>
<p>The Cube Dataset API provides methods to write either a single fact or multiple facts at once:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">interface</span> <span class="nc">Cube</span> <span class="kd">extends</span> <span class="n">Dataset</span><span class="p">,</span> <span class="n">BatchWritable</span><span class="o">&lt;</span><span class="n">Object</span><span class="p">,</span> <span class="n">CubeFact</span><span class="o">&gt;</span> <span class="p">{</span>
 <span class="kt">void</span> <span class="nf">add</span><span class="p">(</span><span class="n">CubeFact</span> <span class="n">fact</span><span class="p">);</span>
 <span class="kt">void</span> <span class="nf">add</span><span class="p">(</span><span class="n">Collection</span><span class="o">&lt;?</span> <span class="kd">extends</span> <span class="n">CubeFact</span><span class="o">&gt;</span> <span class="n">facts</span><span class="p">);</span>
 <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="cube-configuration">
<h2>Cube Configuration<a class="headerlink" href="#cube-configuration" title="Permalink to this headline">🔗</a></h2>
<p>A Cube dataset allows for querying a pre-aggregated view of the data. That view needs to
be configured before any data is written to the Cube. Currently, a view is configured with
a list of dimensions and list of required dimensions using the <a class="reference internal" href="system-custom.html#custom-datasets-properties"><span class="std std-ref">Dataset properties</span></a>.</p>
<p>A Cube can have multiple views configured. They can be altered by updating the dataset
properties using the <span class="xref std std-ref">Dataset RESTful API</span>.</p>
<p>Here’s an example of configuring a pre-aggregated view via the dataset properties:</p>
<a class="reference internal image-reference" href="../../_images/cube-example.png"><img alt="../../_images/cube-example.png" class="align-center" src="../../_images/cube-example.png" style="width: 642px;" /></a>
<p>On the bottom are two Cube dataset properties that correspond to a logical view
(aggregation) that can be defined with the SQL-like statement on the top.</p>
<p>In this example, the view is configured with two dimensions: <code class="docutils literal notranslate"><span class="pre">rack</span></code> and <code class="docutils literal notranslate"><span class="pre">server</span></code>.
Values for both are required: the data of a CubeFact is aggregated in this view only if a
CubeFact has non-null values for both dimensions.</p>
<p>In addition to configuring aggregation views, a Cube can be configured to aggregate
for multiple time resolutions based on the <code class="docutils literal notranslate"><span class="pre">dataset.cube.resolutions</span></code> property, which
takes a comma-separated list of resolution values in seconds, such as <code class="docutils literal notranslate"><span class="pre">1,60,3600</span></code>
(corresponding to 1 second, 1 minute, or 1 hour resolutions):</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">dataset.cube.resolutions=1,60,3600</span>
</pre></div>
</div>
<p>By default, if no <code class="docutils literal notranslate"><span class="pre">dataset.cube.resolutions</span></code> property is provided, a resolution of 1
second is used.</p>
</div>
<div class="section" id="querying-data">
<h2>Querying Data<a class="headerlink" href="#querying-data" title="Permalink to this headline">🔗</a></h2>
<p>Querying data in Cube dataset is the most useful part of it. One can slice, dice and
drill down into the data of the Cube. Use these methods of the API to perform queries:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">interface</span> <span class="nc">Cube</span> <span class="kd">extends</span> <span class="n">Dataset</span><span class="p">,</span> <span class="n">BatchWritable</span><span class="o">&lt;</span><span class="n">Object</span><span class="p">,</span> <span class="n">CubeFact</span><span class="o">&gt;</span> <span class="p">{</span>
 <span class="n">Collection</span><span class="o">&lt;</span><span class="n">TimeSeries</span><span class="o">&gt;</span> <span class="nf">query</span><span class="p">(</span><span class="n">CubeQuery</span> <span class="n">query</span><span class="p">);</span>
 <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>To understand the <code class="docutils literal notranslate"><span class="pre">CubeQuery</span></code> interface, let’s look at an example:</p>
<a class="reference internal image-reference" href="../../_images/cube-example2.png"><img alt="../../_images/cube-example2.png" class="align-center" src="../../_images/cube-example2.png" style="width: 908px;" /></a>
<p>On the right is an example of how to build a Java <code class="docutils literal notranslate"><span class="pre">CubeQuery</span></code> corresponding to the
SQL-like statement shown on the left.</p>
<p>In this example, we query two measurements: <code class="docutils literal notranslate"><span class="pre">cpu.used</span></code> and <code class="docutils literal notranslate"><span class="pre">disk.reads</span></code> and use max
and sum functions to perform aggregation if needed. The query is performed on
<code class="docutils literal notranslate"><span class="pre">rack+server</span></code> aggregated view at 1 minute resolution. The data is selected for those
records that have a rack dimension value of <code class="docutils literal notranslate"><span class="pre">rack1</span></code> and for the given time range. The data is
grouped by <code class="docutils literal notranslate"><span class="pre">server</span></code> values and each resulting time series is limited to 100 data points.</p>
<p>The result of the query is a collection of <code class="docutils literal notranslate"><span class="pre">TimeSeries</span></code>. Each timeseries corresponds to
a specific measurement and a combination of dimension values of those specified in the <code class="docutils literal notranslate"><span class="pre">groupBy</span></code>
part:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">final</span> <span class="kd">class</span> <span class="nc">TimeSeries</span> <span class="p">{</span>
  <span class="kd">private</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">measureName</span><span class="p">;</span>
  <span class="kd">private</span> <span class="kd">final</span> <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="n">dimensionValues</span><span class="p">;</span>
  <span class="kd">private</span> <span class="kd">final</span> <span class="n">List</span><span class="o">&lt;</span><span class="n">TimeValue</span><span class="o">&gt;</span> <span class="n">timeValues</span><span class="p">;</span>
  <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="exploring-data">
<h2>Exploring Data<a class="headerlink" href="#exploring-data" title="Permalink to this headline">🔗</a></h2>
<p>Many times, in order to construct a useful query, you have to explore and discover what
data is available in the Cube. For that, Cube provides exploration APIs to search for
available dimension values and measurements in specific selection of the Cube data:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">interface</span> <span class="nc">Cube</span> <span class="kd">extends</span> <span class="n">Dataset</span><span class="p">,</span> <span class="n">BatchWritable</span><span class="o">&lt;</span><span class="n">Object</span><span class="p">,</span> <span class="n">CubeFact</span><span class="o">&gt;</span> <span class="p">{</span>
 <span class="n">Collection</span><span class="o">&lt;</span><span class="n">DimensionValue</span><span class="o">&gt;</span> <span class="nf">findDimensionValues</span><span class="p">(</span><span class="n">CubeExploreQuery</span> <span class="n">query</span><span class="p">);</span>
 <span class="n">Collection</span><span class="o">&lt;</span><span class="n">String</span><span class="o">&gt;</span> <span class="nf">findMeasureNames</span><span class="p">(</span><span class="n">CubeExploreQuery</span> <span class="n">query</span><span class="p">);</span>
 <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">findDimensionValues</span></code> method finds all dimension values that the data selection
defined by <code class="docutils literal notranslate"><span class="pre">CubeExploreQuery</span></code> has, in addition to those specified in the
<code class="docutils literal notranslate"><span class="pre">CubeExploreQuery</span></code> itself. Each returned value can be added to the original
<code class="docutils literal notranslate"><span class="pre">CubeExploreQuery</span></code> to further drill down into the Cube data.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">findMeasureNames</span></code> method finds all measurements that exist in the data selection specified
within a <code class="docutils literal notranslate"><span class="pre">CubeExploreQuery</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">CubeExploreQuery</span></code> is performed across all aggregation views and allows you to configure
time range, resolution, dimension values to filter by, and limit the returned results
count:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">CubeExploreQuery</span> <span class="n">exploreQuery</span> <span class="o">=</span> <span class="n">CubeExploreQuery</span><span class="p">.</span><span class="na">builder</span><span class="p">()</span>
  <span class="p">.</span><span class="na">from</span><span class="p">()</span>
    <span class="p">.</span><span class="na">resolution</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">TimeUnit</span><span class="p">.</span><span class="na">MINUTES</span><span class="p">)</span>
  <span class="p">.</span><span class="na">where</span><span class="p">()</span>
    <span class="p">.</span><span class="na">dimension</span><span class="p">(</span><span class="s">&quot;rack&quot;</span><span class="p">,</span> <span class="s">&quot;rack1&quot;</span><span class="p">)</span>
    <span class="p">.</span><span class="na">timeRange</span><span class="p">(</span><span class="mi">1423370200</span><span class="p">,</span> <span class="mi">1423398198</span><span class="p">)</span>
  <span class="p">.</span><span class="na">limit</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
  <span class="p">.</span><span class="na">build</span><span class="p">();</span>
</pre></div>
</div>
<p>This query defines the data selection as 1 minute resolution aggregations that have rack
dimension with value <code class="docutils literal notranslate"><span class="pre">rack1</span></code> and the specified time range. It limits the number of
results to 100.</p>
</div>
<div class="section" id="abstractcubehttphandler">
<h2>AbstractCubeHttpHandler<a class="headerlink" href="#abstractcubehttphandler" title="Permalink to this headline">🔗</a></h2>
<p>CDAP comes with an AbstractCubeHttpHandler that can be used to quickly add a Service in
your application that provides a RESTful API on top of your Cube dataset. It is an abstract
class with only a single method to be implemented by its subclass that returns the Cube dataset
to query in:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">protected</span> <span class="kd">abstract</span> <span class="n">Cube</span> <span class="nf">getCube</span><span class="p">();</span>
</pre></div>
</div>
<p>Here’s an example of an application with a Cube dataset and an HTTP Service that provides
RESTful access to it:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">class</span> <span class="nc">AppWithCube</span> <span class="kd">extends</span> <span class="n">AbstractApplication</span> <span class="p">{</span>
  <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">CUBE_NAME</span> <span class="o">=</span> <span class="s">&quot;cube&quot;</span><span class="p">;</span>
  <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">SERVICE_NAME</span> <span class="o">=</span> <span class="s">&quot;service&quot;</span><span class="p">;</span>

  <span class="nd">@Override</span>
  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">configure</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">DatasetProperties</span> <span class="n">props</span> <span class="o">=</span> <span class="n">DatasetProperties</span><span class="p">.</span><span class="na">builder</span><span class="p">()</span>
      <span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;dataset.cube.resolutions&quot;</span><span class="p">,</span> <span class="s">&quot;1,60&quot;</span><span class="p">)</span>
      <span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;dataset.cube.aggregation.agg1.dimensions&quot;</span><span class="p">,</span> <span class="s">&quot;user,action&quot;</span><span class="p">)</span>
      <span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;dataset.cube.aggregation.agg1.requiredDimensions&quot;</span><span class="p">,</span> <span class="s">&quot;user,action&quot;</span><span class="p">).</span><span class="na">build</span><span class="p">();</span>
    <span class="n">createDataset</span><span class="p">(</span><span class="n">CUBE_NAME</span><span class="p">,</span> <span class="n">Cube</span><span class="p">.</span><span class="na">class</span><span class="p">,</span> <span class="n">props</span><span class="p">);</span>

    <span class="n">addService</span><span class="p">(</span><span class="n">SERVICE_NAME</span><span class="p">,</span> <span class="k">new</span> <span class="n">CubeHandler</span><span class="p">());</span>
  <span class="p">}</span>

  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kd">class</span> <span class="nc">CubeHandler</span> <span class="kd">extends</span> <span class="n">AbstractCubeHttpHandler</span> <span class="p">{</span>
    <span class="nd">@UseDataSet</span><span class="p">(</span><span class="n">CUBE_NAME</span><span class="p">)</span>
    <span class="kd">private</span> <span class="n">Cube</span> <span class="n">cube</span><span class="p">;</span>

    <span class="nd">@Override</span>
    <span class="kd">protected</span> <span class="n">Cube</span> <span class="nf">getCube</span><span class="p">()</span> <span class="p">{</span>
      <span class="k">return</span> <span class="n">cube</span><span class="p">;</span>
    <span class="p">}</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Example of the query in JSON format:</p>
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="nt">&quot;aggregation&quot;</span><span class="p">:</span> <span class="s2">&quot;rack+server&quot;</span><span class="p">,</span>
    <span class="nt">&quot;startTs&quot;</span><span class="p">:</span> <span class="mi">1423370200</span><span class="p">,</span>
    <span class="nt">&quot;endTs&quot;</span><span class="p">:</span>   <span class="mi">1423398198</span><span class="p">,</span>
    <span class="nt">&quot;measurements&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nt">&quot;cpu.used&quot;</span><span class="p">:</span> <span class="s2">&quot;MAX&quot;</span><span class="p">,</span> <span class="nt">&quot;disk.reads&quot;</span><span class="p">:</span> <span class="s2">&quot;SUM&quot;</span><span class="p">},</span>
    <span class="nt">&quot;resolution&quot;</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>
    <span class="nt">&quot;dimensionValues&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nt">&quot;rack&quot;</span><span class="p">:</span> <span class="s2">&quot;rack1&quot;</span><span class="p">},</span>
    <span class="nt">&quot;groupByDimensions&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;server&quot;</span><span class="p">],</span>
    <span class="nt">&quot;limit&quot;</span><span class="p">:</span> <span class="mi">100</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Example of the response in JSON format (pretty-printed to fit):</p>
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="p">{</span>
        <span class="nt">&quot;measureName&quot;</span><span class="p">:</span> <span class="s2">&quot;disk.reads&quot;</span><span class="p">,</span>
        <span class="nt">&quot;dimensionValues&quot;</span><span class="p">:</span> <span class="p">{</span>
            <span class="nt">&quot;server&quot;</span><span class="p">:</span> <span class="s2">&quot;server1&quot;</span>
        <span class="p">},</span>
        <span class="nt">&quot;timeValues&quot;</span><span class="p">:</span> <span class="p">[</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370200</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">969</span>
            <span class="p">},</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370260</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">360</span>
            <span class="p">}</span>
        <span class="p">]</span>
    <span class="p">},</span>
    <span class="p">{</span>
        <span class="nt">&quot;measureName&quot;</span><span class="p">:</span> <span class="s2">&quot;disk.reads&quot;</span><span class="p">,</span>
        <span class="nt">&quot;dimensionValues&quot;</span><span class="p">:</span> <span class="p">{</span>
            <span class="nt">&quot;server&quot;</span><span class="p">:</span> <span class="s2">&quot;server2&quot;</span>
        <span class="p">},</span>
        <span class="nt">&quot;timeValues&quot;</span><span class="p">:</span> <span class="p">[</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370200</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">23</span>
            <span class="p">},</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370260</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">444</span>
            <span class="p">}</span>
        <span class="p">]</span>
    <span class="p">},</span>
    <span class="p">{</span>
        <span class="nt">&quot;measureName&quot;</span><span class="p">:</span> <span class="s2">&quot;cpu.used&quot;</span><span class="p">,</span>
        <span class="nt">&quot;dimensionValues&quot;</span><span class="p">:</span> <span class="p">{</span>
            <span class="nt">&quot;server&quot;</span><span class="p">:</span> <span class="s2">&quot;server1&quot;</span>
        <span class="p">},</span>
        <span class="nt">&quot;timeValues&quot;</span><span class="p">:</span> <span class="p">[</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370200</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">50</span>
            <span class="p">},</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370260</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">55</span>
            <span class="p">}</span>
        <span class="p">]</span>
    <span class="p">},</span>
    <span class="p">{</span>
        <span class="nt">&quot;measureName&quot;</span><span class="p">:</span> <span class="s2">&quot;cpu.used&quot;</span><span class="p">,</span>
        <span class="nt">&quot;dimensionValues&quot;</span><span class="p">:</span> <span class="p">{</span>
            <span class="nt">&quot;server&quot;</span><span class="p">:</span> <span class="s2">&quot;server2&quot;</span>
        <span class="p">},</span>
        <span class="nt">&quot;timeValues&quot;</span><span class="p">:</span> <span class="p">[</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370200</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">12</span>
            <span class="p">},</span>
            <span class="p">{</span>
                <span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="mi">1423370260</span><span class="p">,</span>
                <span class="nt">&quot;value&quot;</span><span class="p">:</span> <span class="mi">56</span>
            <span class="p">}</span>
        <span class="p">]</span>
    <span class="p">}</span>
<span class="p">]</span>
</pre></div>
</div>
<p class="rubric">Examples of Using Cube Dataset</p>
<p>An example of using a Cube Dataset is included in the CDAP Guide <span class="xref std std-ref">Data Analysis with
OLAP Cube</span>.</p>
</div>
</div>

</div>
    <div class="col-md-2">
      <div id="right-sidebar" class="bs-sidenav scrollable-y" role="complementary">
        <div id="localtoc-scrollspy">
        </div>
      </div>
    </div></div>
</div>
<!-- block main content end -->
<!-- block footer -->
<footer class="footer">
      <div class="container">
        <div class="row">
          <div class="col-md-2 footer-left"><a title="Dataset Permissions" href="permissions.html" />Previous</a></div>
          <div class="col-md-8 footer-center"><a class="footer-tab-link" href="../../table-of-contents/../../reference-manual/licenses/index.html">Copyright</a> &copy; 2014-2020 Cask Data, Inc.&bull; <a class="footer-tab-link" href="//docs.cask.co/cdap/6.1.1/cdap-docs-6.1.1-web.zip" rel="nofollow">Download</a> an archive or
<a class="footer-tab-link" href="//docs.cask.co/cdap">switch the version</a> of the documentation
          </div>
          <div class="col-md-2 footer-right"><a title="MapReduce Programs" href="../mapreduce-programs.html" />Next</a></div>
        </div>
      </div>
    </footer>
<!-- block footer end -->
<script type="text/javascript" src="../../_static/bootstrap-3.3.6/js/bootstrap.min.js"></script><script type="text/javascript" src="../../_static/js/bootstrap-sphinx.js"></script><script type="text/javascript" src="../../_static/js/abixTreeList-2.js"></script><script type="text/javascript" src="../../_static/js/cdap-dynamicscrollspy-4.js"></script><script type="text/javascript" src="../../_static/js/cdap-version-menu.js"></script><script type="text/javascript" src="../../_static/js/copy-to-clipboard.js"></script><script type="text/javascript" src="../../_static/js/jquery.mousewheel.min.js"></script><script type="text/javascript" src="../../_static/js/jquery.mCustomScrollbar.js"></script><script type="text/javascript" src="../../_static/js/js.cookie.js"></script><script type="text/javascript" src="../../_static/js/tabbed-parsed-literal-0.2.js"></script><script type="text/javascript" src="../../_static/js/cdap-onload-javascript.js"></script><script type="text/javascript" src="../../_static/js/cdap-version-menu.js"></script>
    <script src="https://cdap.gitee.io/docs/cdap/json-versions.js"/></script>
  </body>
</html>